package day14.CountDownLatchDemo01;

import java.util.concurrent.CountDownLatch;

/**
 * @author Xiao
 * @date 2021/8/8
 */
public class CountDownLatchDemo {
    /**
     * 测试类：开启4条线程，创建CountDownLatch的对象传递给4条线程
     */
    public static void main(String[] args) {
        //创建CountDownLatch对象，需要传递4条线程，等待3条线程
        //底层定义了一个计数器，此时计数器的值为3
        CountDownLatch cd = new CountDownLatch(3);
        MotherThread mt = new MotherThread(cd);
        ChildThread1 ct1 = new ChildThread1(cd);
        ChildThread2 ct2 = new ChildThread2(cd);
        ChildThread3 ct3 = new ChildThread3(cd);
        Thread tm = new Thread(mt);
        Thread t1 = new Thread(ct1);
        Thread t2 = new Thread(ct2);
        Thread t3 = new Thread(ct3);
        tm.setName("妈妈");
        t1.setName("大毛");
        t2.setName("二毛");
        t3.setName("小明");
        tm.start();
        t1.start();
        t2.start();
        t3.start();
    }
}
